/*
 * Copyright (c) 2008 by 1eEurope (Switzerland) AG, Thalwil
 *
 * Customer:	1eEurope (Switzerland) AG
 * Project:		BKS
 * Created:		30.09.2008, WBL
 *
*/

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace By1eEurope.BKS.UserControlZone
{
    /// <summary>
    /// Value class of the UserControlZone Field Type
    /// </summary>
    public class UserControlZoneValue
    {
        private IDictionary<string,string> controls;

        public UserControlZoneValue() { }

        public UserControlZoneValue(string value)
        {
            this.controls = new Dictionary<string, string>();
            if (!string.IsNullOrEmpty(value))
            {
                string[] pairs = value.Split(new string[] { "##;" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < pairs.Length; i++)
                {
                    string[] pair = pairs[i].Split(new string[] { "#;" }, StringSplitOptions.RemoveEmptyEntries);
                    if (pair.Length == 2)
                    {
                        this.controls.Add(pair[0], pair[1]);
                    }
                }
            }
        }

        public override string ToString()
        {
            if (this.controls == null)
                return string.Empty;
            else
            {
                string save = string.Empty;
                foreach (string key in this.controls.Keys)
                {
                    save += key + "#;" + this.controls[key] + "##;";
                }
                return save;
            }
        }

        public IDictionary<string, string> Controls
        {
            get { return this.controls; }
            set { this.controls = value; }
        }
    }
}
